import {Component, OnInit} from '@angular/core';
import {ElasticSearchService} from "../../service/es/elastic-search.service";
import {Router} from "@angular/router";
import {NzMessageService} from "ng-zorro-antd/message";

@Component({
  selector: 'app-configuration',
  templateUrl: './configuration.component.html',
  styleUrls: ['./configuration.component.scss']
})
export class ConfigurationComponent implements OnInit {

  param = {
    url: 'http://localhost:9200',
    authentication: false,
    username: '',
    password: '',
  }

  constructor(
    private es: ElasticSearchService,
    private router: Router,
    private message: NzMessageService,
  ) {
  }

  ngOnInit(): void {
  }

  submitForm() {
    this.es.checkAuthentication(this.param).subscribe(r => {
      this.es.saveConfiguration(this.param);
      this.es.saveAuthentication(r);
      this.router.navigate(['/'])
    }, () => {
      this.message.error('配置失败')
    })

  }
}
